// page{}s/express/express.js
import { Order } from "../../models/order.js"
import { Express } from "../../models/express.js"
import { Enum } from "../../utils/enum.js"
var order = new Order()
var express = new Express()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderID:'',
    fromWhere:'',
    compDefault: "顺风",
    numberDefault: "123456fromUserMock"
  },

  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: "卖书订单发货"
    })
    this.setData({
      orderID:options.id,
      fromWhere: options.fromWhere
    })
  },
  
   formSubmit(event) {
    var expressComp = event.detail.value.expressComp
    var expressNo = event.detail.value.expressNo

    if (!expressComp || !expressNo) {
      express.toast("请将物流信息填写完整", "none")
      return
    }

    var formId = event.detail.formId

    var data = {
      order_id: this.data.orderID,
      comp_name: expressComp,
      express_no: expressNo,
      form_id: formId
    }

    express.toExpress(data, (res) => {
      if (express.processRes(res.statusCode)) {
        express.toast("订单发货成功")
        order.setUpdateStorage(this.data.fromWhere)
        setTimeout(function () {
          wx.navigateBack({
            delta: 1
          })
        }, 1000)
      } else {
        express.toast("订单发货失败，请稍后再试","none")
      }
    })
  }
})